package com.iyohei.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.iyohei.entry.User;
import com.iyohei.service.UserService;

@RestController
public class HelloWorldController {
	
	@Autowired
	private UserService userService;
	
	
	@RequestMapping(path="/fxh",method= {RequestMethod.GET})
	public String helloWorld(){
		System.out.println("helloWorld!");
		return "helloWorld!";
	}
	
	@RequestMapping(path="/getUserById/{id}",method= {RequestMethod.GET})
	@ResponseBody
	public User userGetById(@PathVariable("id")long id){
		System.out.println("获取user:"+id);
		return userService.getUserById(id);
	}
	
	@RequestMapping(path="/getById/{id}",method= {RequestMethod.GET})
	@ResponseBody
	public User getById(@PathVariable("id")long id){
		System.out.println("获取user:"+id);
		return userService.getById(id);
	}
	
	@RequestMapping(path="/deleteById/{id}",method= {RequestMethod.GET})
	public String deleteById(@PathVariable("id")long id) {
		System.out.println("进入deleteById方法:" + id);
		long resultNum = userService.deleteById(id);
		System.out.println("受影响条数:" + resultNum);
		return null;
		
	}
	
}
